package cn.itcast.tanhua.mytanhuadubboservice.api;


import cn.itcast.tanhua.enums.IdType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

//生成自增长的id，原理：使用redis的自增长值
@Service
public class IdService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public Long createId(IdType idType) {
        String idKey = "TANHUA_ID_" + idType.toString();
        Long id=this.redisTemplate.opsForValue().increment(idKey);
        System.out.println(id);
        return id;
    }

}